package com.hngy.xpq.chatdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;

import com.hngy.xpq.chatdemo.adapter.FriendAdapter;
import com.hngy.xpq.chatdemo.bean.Friend;

import java.util.ArrayList;
import java.util.List;

public class FriendActivity extends AppCompatActivity {

    RecyclerView friend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend);
        init();
    }

    private void init() {
        friend = findViewById(R.id.friend);
        initFriendAdapter(getListFriend());
    }

    private void initFriendAdapter(List<Friend> listFriend) {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        friend.setLayoutManager(layoutManager);
        FriendAdapter adapter = new FriendAdapter(listFriend);
        friend.setAdapter(adapter);
    }

    private List<Friend> getListFriend() {
        List<Friend> list = new ArrayList<>();
        Friend friend = new Friend();
        friend.setNotes("小许");
        list.add(friend);
        Friend friend2 = new Friend();
        friend2.setNotes("小张");
        list.add(friend2);
        Friend friend3 = new Friend();
        friend3.setNotes("小王");
        list.add(friend3);
        Friend friend4 = new Friend();
        friend4.setNotes("小李");
        list.add(friend4);
        return list;
    }
}